import { $rp } from '@/utils/constants';

export default (note) => {
  const errs = ['贡献提醒参数错误'];
  if (note.spaceInfo.err) errs.push(note.spaceInfo.msg);
  if (note.noteInfo.err) errs.push(note.noteInfo.msg);

  if (errs.length > 1) return { id: note.id, err: true, msg: errs.join(', ') };

  let desc = '';
  const rootPath = `/${$rp.SPACES}/${note.spaceInfo.id}/${$rp.SPACE_CONTRIBUTIONS}/${note.noteInfo.id}`;

  if (note.noteInfo.action === 'accept') desc = '被采纳';
  else if (note.noteInfo.action === 'close') desc = '被关闭';
  else errs.push('错误的参数 action');

  return {
    type: note.type,
    id: note.id,
    desc,
    root: { title: note.noteInfo.title, path: rootPath },

    read: note.read,
    created_at: note.created_at,
    updated_at: note.updated_at,
  };
};
